// 下载文件
export function downloadFile(url, id) {
  const a = document.createElement('a')
  a.setAttribute('href', url)
  a.setAttribute('target', '_blank')
  a.setAttribute('id', id)
  a.click()
  setTimeout(() => {
    a.remove()
  }, 100)
}

//流文件下载
// data 数据；fileName文件名
export const blobFileDown = (data, fileName) => {
  var type = 'application/vnd.ms-excel;charset=utf-8'
  let blob = new Blob([data], {
    type: type,
  }) //指定格式为vnd.ms-excel
  let downloadElement = document.createElement('a')
  let href = window.URL.createObjectURL(blob) //创建下载的链接
  downloadElement.download = fileName // 下载后文件名 // 下载后文件名
  downloadElement.href = href
  document.body.appendChild(downloadElement)
  downloadElement.click() //点击下载
  document.body.removeChild(downloadElement) //下载完成移除元素
  window.URL.revokeObjectURL(href) //释放掉blob对象
}
